package tuples;

import java.util.Comparator;

/**
 *
 * @author Shimu
 * @date 9-Oct-2012
 */
public class Triple<T1, T2, T3> extends Pair<T1, T2> {
    
    private T3 ELEMENT3;
    
    public Triple(T1 element1, T2 element2, T3 element3) {
        super(element1, element2);
        this.ELEMENT3 = element3;
    }
    
    /**
     * Returns the third element
     * @return 
     */
    public T3 getThird() {
        return this.ELEMENT3;
    }
    
    public static <T extends Comparable> Comparator<Triple<?, ?, T>> 
            getThirdComparator(Class<T> c) {
        return new Comparator<Triple<?, ?, T>>(){

            public int compare(Triple<?, ?, T> o1, Triple<?, ?, T> o2) {
                return o1.getThird().compareTo(o2.getThird());
            }
        };
    }
    
    @Override
    public String toString() {
        return String.format("Triple: (%s, %s, %s)", String.valueOf(getFirst()),
                String.valueOf(getSecond()), String.valueOf(getThird()));
    }
}
